{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="content"}
<div class="t-a-wait-con">
    <div class="tablesWrap">
    	<div class="tables-searchbox">
            <div class="t-a-wait-top">
                <form action="" method="post" id="rank_waiting">
                <div class="t-a-wait-top-li" style="width:400px;">
                    <div class="formitems inline">
                        <label class="fi-name" style="width:70px; font-weight:normal;">添加时间：</label>
                        <div class="form-controls" style="margin-left:80px;">
				            <input type="text" style="width:120px;" autocomplete="off" class="Wdate" name="start_time" value="{if $start_time}{date('Y-m-d',$start_time)}{/if}" onclick="WdatePicker({ dateFmt:'yyyy-MM-dd'})">

                            <span class="fi-text">-</span>

                            <input type="text" style="width:120px;" autocomplete="off" class="Wdate" name="end_time" value="{if $end_time}{date('Y-m-d',$end_time)}{/if}" onclick="WdatePicker({ dateFmt:'yyyy-MM-dd'})">
                        </div>
                    </div>
                </div>

                <div class="t-a-wait-top-li" style=""><input type="hidden" name="submit" value="search" /><button class="btn"><i class="gicon-search"></i>搜索</button> </div>
              </form>
            </div>
        </div>
        <table class="wxtables">
            <colgroup>
            <col width="4%">
            <col width="10%">
            <col width="10%">
            <col width="18%">
            <col width="8%">
            <col width="10%">
            <col width="20%">
            </colgroup>
            <thead>
                <tr>
                    <td>选择</td>
                    <td>活动名称</td>
                    <td>活动有效期</td>
                    <td>赠送</td>
                    <td>状态</td>
                    <td>添加时间</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
				{foreach from=$buy_give_list item=buy_give}
                <tr>
                    <td><input type="checkbox" class="checkbox" value='{$buy_give.buy_give_id}' name="a[]"></td>
                    <td>{$buy_give.title}</td>
                    <td>{$buy_give.start_time|date_format:"%Y-%m-%d %H:%M:%S"}至{$buy_give.end_time|date_format:"%Y-%m-%d %H:%M:%S"}</td>
                    <td>{$buy_give.send_desc}</td>
                    <td>{$buy_give.isuse_desc}</td>
                    <td>{$buy_give.addtime|date_format:"%Y-%m-%d %H:%M:%S"}</td>
                    <td>
						<a href="/AcpGroupBuy/get_buy_give_detail/buy_give_id/{$buy_give.buy_give_id}" class="btn" title="查看活动明细">查看活动明细</a>
						<a href="/AcpBuyGive/edit_buy_give/buy_give_id/{$buy_give.buy_give_id}" class="btn" title="修改">修改</a>
						<a href="/AcpBuyGive/buy_give_stat/buy_give_id/{$buy_give.buy_give_id}" class="btn" title="查看统计">查看统计</a>
                    </td>
                </tr>
                {foreachelse}
					<tr><td colspan="11">没有符合条件的镖金券</td></tr>
                {/foreach}
            </tbody>
        </table>
        <!-- end wxtables -->
        <div class="tables-btmctrl clearfix">
        	<a href="javascript:;" onclick='buy_give_link()' class="btn btn-blue" title="复制活动链接">复制活动链接</a>
            <div class="fr">
                <div class="paginate">
                    {$show}
                </div>
                <!-- end paginate -->
            </div>
        </div>
        <!-- end tables-btmctrl -->
    </div>
    <!-- end tablesWrap -->
</div>
{/block}

{block name="js"}
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
{literal}
<script>
//全选
function Select(){
	var sel=document.getElementsByName("a[]");
	for(var i=0;i<sel.length;i++){
		sel[i].checked=true;
	}
}
//取消全选
function Cancel(){
	var sel=document.getElementsByName("a[]");
	for(var i=0;i<sel.length;i++){
		sel[i].checked=false;
	}
}

function set_is_enable(id, is_enable)
{
	opt = (is_enable == 1) ? '激活' : '禁用';
	$.jPops.confirm(
	{
		 title:"提示",
		 content:"您确定要执行该操作吗？",
		 okBtnTxt:"确定",
		 cancelBtnTxt:"取消",
		 callback:function(r)
		 {
			 if(r)
			 {
				 $.post('/AcpUserAjax/set_user_is_enable', {"user_id":id, "is_enable":is_enable}, function(data, textStatus)
				 {
					if (data == 'success')
					{
						alert('恭喜您，' + opt + '成功！');
						location.reload();
					}
					else
					{
						alert('对不起，' + opt + '失败');
					}
				});
			 }
			 return true;
		 }
	 });
}

function batch_set_is_enable(is_enable)
{
	opt = (is_enable == 1) ? '激活' : '禁用';
	$.jPops.confirm(
	{
		 title:"提示",
		 content:"您确定要执行这些操作吗？",
		 okBtnTxt:"确定",
		 cancelBtnTxt:"取消",
		 callback:function(r)
		 {
			 if(r)
			 {
				 var ids = '';
				 var count = 0;
				 $('input[name="a[]"]:checked').each(function(){
					 count ++;
					 ids += $(this).val() + ',';
				 });

				 if (!count)
				 {
					 alert('对不起，请选择至少一项进行操作！');
					 return;
				 }

				 ids = ids.substr(0, ids.length - 1);

				 $.post('/AcpUserAjax/batch_set_user_is_enable', {"user_ids":ids, "is_enable":is_enable}, function(data, textStatus)
				 {
					if (data == 'success')
					{
						alert('恭喜您，' + opt + '成功！');
						location.reload();
					}
					else
					{
						alert('对不起，' + opt + '失败');
					}
				});
			 }
			 return true;
		 }
	 });
}

//复制商品链接
function buy_give_link()
{
    var link = 'http://' + document.domain + '/FrontCoupon/buy_gifts_list';
    $.jPops.custom({
        title:"请复制链接",  
        content:'<div>活动链接：' + link + '</div>',
        okBtnTxt:"复制",  
        cancelBtnTxt:"关闭",  
        callback:function(r)
        {
            if(r)
            {
                text = link;
                copy_text('jpops-btn-ok');
            }
            else
            {
                return true;  
            }
        }
    });
}
function copy_text(id)
    {
        var clipboard = new Clipboard('#' + id, {
            text: function() {
                return text;
            }
        });

        clipboard.on('success', function(e) {
            console.log(e);
            alert('复制成功');
        });

        clipboard.on('error', function(e) {
            console.log(e);
            alert('复制失败，请手动复制');
        });
    } 
</script>
{/literal}
{/block}

{block name="css"}
<link rel="stylesheet" href="/Public/Css/acp/AcpUser/audit_waiting.css" type="text/css" />
{/block}
